"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Finch = void 0;
const http = require("http");
const https = require("https");
const finch_log_1 = require("finch-log");
const function_createRequestListener_1 = require("./function_createRequestListener");
class Finch {
    constructor(option) {
        this.StaticDir = undefined;
        this.Logger = new finch_log_1.FinchLogger({ maxFiles: 200, maxLines: 8000, });
        this.Handles = {};
        this.allFunctions = [];
        if (!option.disableLogger) {
            this.Logger = new finch_log_1.FinchLogger({
                maxLines: 8000,
                maxFiles: 200,
                logStorageDir: './FinchServerLog'
            });
        }
        this.StaticDir = option.staticFileDir;
        if (option.httpsOption) {
            this.Server = https.createServer(option.httpsOption, (0, function_createRequestListener_1.createRequestListener)(this));
        }
        else {
            this.Server = http.createServer((0, function_createRequestListener_1.createRequestListener)(this));
        }
    }
    listen(port) {
        this.Server.listen(port);
        this.Logger.log(`Finch 正在监听端口 ${port}`);
    }
    use(handle, middleWare) {
        if (!this.Handles.hasOwnProperty(handle)) {
            this.Handles[handle] = [];
            for (let a in this.allFunctions) {
                this.Handles[handle].push(this.allFunctions[a]);
            }
        }
        this.Handles[handle].push(middleWare);
    }
    all(middleWare) {
        this.allFunctions.push(middleWare);
        for (let a in this.Handles) {
            this.Handles[a].push(middleWare);
        }
    }
}
exports.Finch = Finch;
